<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/10
 * Time: 15:33
 */
class JiliangOauthInterf extends UserOauthBaseInterf
{
    private $accountId;
    private $realName;
    private $number;

    public function callOauthIntf()
    {
        //验证用户姓名和学号是否在gc_user表中存在
        $condition = array(
            'account_id' => $this->accountId,
            'real_name' => $this->realName,
            'number' => strtoupper($this->number)
        );
        $userId = M('User')->where($condition)->getField('user_id');
        if (!$userId) {
            return array('err_code' => 1000, 'err_msg' => '当前用户不存在,不能通过认证!');
        }

        $res = $this->doCallBack($userId);
        return $res;
    }

    public function doCallBack($userId)
    {
        $res = M('User')->where(array('user_id'=>$userId))->save(array('status' => 2));
        if ($res === false) {
            return array('err_code' => 1001, 'err_msg' => '认证失败!');
        }

        //更新微信用户数据
        $mWechatUser = D('Wechat/WechatUser');
        $condition = array (
            'user_id' => $userId,
            'wechat_user_id' => session('wechatUserId'),
        );
        $mWechatUser->update($condition);
        session('userId', $userId);

        return array('err_code' => 200, 'err_msg' => '认证成功!');
    }

    public function setProperties($src)
    {
        $src_vars = is_object($src) ? get_object_vars($src) : $src;
        foreach ($src_vars as $name => $value) {
            if (property_exists($this, $name)) {
                $this->$name = $value;
            }
        }
        return $this;
    }
}